package com.ld.security.auth.server.modules.sys.service.impl;

import com.ld.security.auth.server.modules.sys.entity.SysClient;
import com.ld.security.auth.server.modules.sys.service.ISysClientService;
import com.ld.security.common.mybatis.constant.SqlCondition;
import com.ld.security.common.core.util.UuidUtil;
import com.ld.security.common.mybatis.base.service.*;
import com.ld.security.common.mybatis.core.wrapper.EntityWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
class SysClientServiceImpl extends ISuperServiceImpl<SysClient> implements
        ISysClientService {


    @Override
    public SysClient findByUsername(String username) {
        EntityWrapper ew = this.getWrapper();
        ew.addField("username", SqlCondition.eq, username);
        return superMapping.selectOne(ew);
    }


    @Override
    public int save(SysClient entity) {
        SysClient sysClient = this.getById(entity.getId());
        if(sysClient != null){
            if(entity.getPassword().equals(sysClient.getPassword())){
                //密码相同取消加密
                entity.setPassword(null);
            }
        }

        return super.save(entity);
    }

}
